package com.googlecode.fxutils;

/*
Copyright (c) 2014, Carlos Eduardo Klock.
All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other
materials provided with the distribution.

3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific
prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

import com.googlecode.fxutils.FxUtils.SameSize;
import java.util.Arrays;
import java.util.List;
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Insets;
import javafx.geometry.Orientation;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.Pane;
import javafx.scene.layout.StackPane;
import javafx.scene.web.WebEngine;
import javafx.scene.web.WebView;
import javafx.stage.Stage;
import javafx.stage.StageStyle;

/**
 * Tests/Examples.
 */
public class Main extends Application {

    public static final String APP_NAME = "fxutils";

    @Override
    public void start(final Stage primaryStage) {
        Button messageDialog1 = messageDialog1(primaryStage);
        Button optionDialog1 = optionDialog1(primaryStage);
        Button webViewDialog1 = webViewDialog1(primaryStage);

        StackPane root = new StackPane();
        List<Button> buttons = Arrays.asList(messageDialog1, optionDialog1, webViewDialog1);
        Pane vbox = FxUtils.createButtonPane(Orientation.VERTICAL, buttons, Pos.CENTER, 30, SameSize.WIDTH);
        root.getChildren().add(vbox);

        Scene scene = new Scene(root, 300, 250);

        primaryStage.setTitle(APP_NAME);
        primaryStage.setScene(scene);
        primaryStage.show();
    }

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        launch(args);
    }

    static Button messageDialog1(final Stage stage) {
        Button b = new Button();
        b.setText("Show Message Dialog");
        b.setOnAction(new EventHandler<ActionEvent>() {
            @Override
            public void handle(ActionEvent event) {
                String option = DialogUtils.showMsgDialog(stage, "Hello World!");
                System.out.println("Clicked button = " + option);
            }
        });
        return b;
    }

    static Button optionDialog1(final Stage stage) {
        Button b = new Button();
        b.setText("Show Option Dialog");
        b.setOnAction(new EventHandler<ActionEvent>() {
            @Override
            public void handle(ActionEvent event) {
                DialogProperties properties = DialogProperties.builder(stage).title("Hello").build();
                String option = DialogUtils.showOptionDialog(properties, "Hello World!", "OK", "Cancel");
                System.out.println("Clicked button = " + option);
            }
        });
        return b;
    }

    static Button webViewDialog1(final Stage stage) {
        Button b = new Button();
        b.setText("Show WebView Dialog");
        b.setOnAction(new EventHandler<ActionEvent>() {
            @Override
            public void handle(ActionEvent event) {
                WebView webview = new WebView();
                WebEngine engine = webview.getEngine();
                engine.load("https://code.google.com/p/fxutils/");

                DialogProperties properties = DialogProperties.builder(stage)
                        .title("WebView Dialog")
                        .decoration(StageStyle.DECORATED)
                        .css("-fx-background-color:white;")
                        .padding(Insets.EMPTY)
                        .build();
                String option = DialogUtils.showOptionDialog(properties, webview, "OK");
                System.out.println("Clicked button = " + option);
            }
        });
        return b;
    }

}
